<template>
  <!-- 好生活资金池-详情-好生活结佣记录-->
  <div class="efCommDetail">
    <brokerInfo :infos="info"></brokerInfo>
    <tableList
      :tableData="tableData"
      :tableInfos="tableInfos"
      :tableFormatter="tableFormatter"
      :hasSera="true"
    ></tableList>
  </div>
</template>

<script type="text/ecmascript-6">
import brokerInfo from "./brokerInfo";
import tableList from "../../common/tableList";
import utils from "@/common/utils.js";
import api from "@/api/apiPath";
export default {
  components: {
    brokerInfo,
    tableList
  },
  data() {
    return {
      tableData: [],
      firstFlag: true,
      tableInfos: [
        { label: "批次号", prop: "batchCode" },
        { label: "交易及佣金确认时间", prop: "auditTime" },
        { label: "结佣类别", prop: "brokerageNodeName" },
        { label: "应结佣金（元）", prop: "easyLifeAmount" },
        { label: "应结前佣佣金（元）", prop: "easyLifeFrontAmount" },
        { label: "应结后佣佣金（元）", prop: "easyLifeAfterAmount" },
        { label: "待结佣金（元）", prop: "easyLifeAmountPaying" }
      ],
      info: {}
    };
  },
  created() {},
  mounted() {},
  methods: {
    tableFormatter(prop, val) {
      let moneyFormatter = [
        "easyLifeAmount",
        "easyLifeFrontAmount",
        "easyLifeAfterAmount",
        "easyLifeAmountPaying"
      ];
      if (moneyFormatter.includes(prop)) {
        return  this.formatMoney(val);
      }
       if(prop == 'auditTime'){
        return utils.getTimeString(val)
      }
      if (prop === "brokerageNodeName") {
        return val ? val + "结佣" : val;
      }
      return val;
    },
    formatMoney(val){
      return  val? utils.formatMoney(val)+"元": "0.00 元"
    },
    searchList() {
      this.axios
        .get(api.getCashPoolEfCommList + "/" + this.userInfo.orderId)
        .then(res => {
          if (res.data.code == 200) {
            this.firstFlag = false;
            this.tableData = res.data.data;
          }
        });
    },
    getUserInfo(val) {
      let {
        customerName,
        customerPhone,
        devName,
        housePrise,
        actualPayment,
        cellName,
        easyLifeBrokerage,
        easyLifeFrontAmount,
        easyLifeAfterAmount
      } = val;
      this.info = {
        客户姓名: customerName,
        电话: utils.formatPhoneNumber(customerPhone),
        楼盘: devName,
        房款:  this.formatMoney(housePrise) ,
        成交价: this.formatMoney(actualPayment) ,
        房间号: cellName,
        "好生活佣金（元）": this.formatMoney(easyLifeBrokerage),
        "前佣（元）": this.formatMoney(easyLifeFrontAmount),
        "后佣（元）": this.formatMoney(easyLifeAfterAmount)
          
      };
    }
  },
  props: ["userInfo", "active"],
  watch: {
    active(val) {
      if (this.firstFlag && val) {
        this.searchList();
      }
    },
    allInfo(val) {
      this.getUserInfo(val);
    }
  },
  computed: {
    allInfo() {
      return this.userInfo.allInfo;
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="stylus"></style>
